home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-03-20 | 5.0 KB | 203 lines | [TEXT/KAHL] |
- //#define DEBUG 1
- // scrolling StyledTEXT procedures for 'puriTEXT'
- // Copyright (C) 1994 by Mizutori Tetsuya, 94/3/9, 94/3/21
-
- #include "Defines.h"
-
- // Prototypes (scrollTE.c)
- /***** scroll TEXT *****/
- void SetupText( WindowPtr window, short textID, Rect *rect, TEHandle *teHandle );
- short SetupLinePos( WindowPtr window, TEHandle teHndl, Handle *posHndl );
- void TEScrollProc( WindowPtr window, Point thePoint );
- pascal void myScrollProc( ControlHandle theControl, short thePart );
- void SetControl( ControlHandle theControl, short *shift );
-
- // !!! CAUTION !!!
- // Some procedure depends on the 'myWindowRecord'.
- // The fields myWindowRecord.{userCntl,userTE,posHndl} are required.
- // !!! CAUTION !!!
-
- /***** setup styled text *****/
- void SetupText( WindowPtr window, short textID, Rect *rect, TEHandle *teHandle )
- {
- TEHandle teHndl;
- StScrpHandle stHndl;
- Rect destRect, viewRect;
- Handle textHandle, stylHandle;
- FontInfo fontInfo;
- Boolean textStyled;
- GrafPtr oldPort;
-
- GetPort( &oldPort );
- SetPort( (GrafPtr) window );
-
- textHandle = GetResource('TEXT',textID);
- stylHandle = GetResource('styl',textID);
- HLock(textHandle);
- HLock(stylHandle);
-
- if ( stylHandle != nil ) textStyled = true; else textStyled = false;
-
- // textStyled = false;
-
- destRect = *rect;
- viewRect = destRect;
-
- if ( textStyled ) {
- teHndl = TEStylNew( &destRect, &viewRect );
- stHndl = (StScrpHandle) stylHandle;
- TEStylInsert( *textHandle, SizeResource(textHandle), stHndl, teHndl );
- } else {
- teHndl = TENew( &destRect, &viewRect );
- TextFont(geneva);
- TextSize(9);
- GetFontInfo(&fontInfo);
- (**teHndl).txFont = geneva;
- (**teHndl).txSize = 9;
- (**teHndl).fontAscent = fontInfo.ascent;
- (**teHndl).lineHeight = fontInfo.ascent + fontInfo.descent + fontInfo.leading;
- TESetText( *textHandle, SizeResource(textHandle), teHndl );
- }
-
- HUnlock(textHandle);
- ReleaseResource(textHandle);
- if ( textStyled ) {
- HUnlock(stylHandle);
- ReleaseResource(stylHandle);
- }
-
- SetPort( oldPort );
-
- *teHandle = teHndl;
- }
-
- short SetupLinePos( WindowPtr window, TEHandle teHndl, Handle *posHndl )
- {
- short **pHndl;
- short *p;
- short i,k,textHeight,viewHeight;
-
- textHeight = TEGetHeight( (long)(**teHndl).nLines, 1L, teHndl );
- viewHeight = (**teHndl).viewRect.bottom - (**teHndl).viewRect.top;
-
- pHndl = (short **) NewHandle( ((**teHndl).nLines+1) * sizeof( short ) );
-
- HLock( (Handle) pHndl );
- p = *pHndl;
-
- p[0] = 0;
- if ( textHeight <= viewHeight ) i = 0;
- else
- for (i=1;i<(**teHndl).nLines+1;++i) {
- k = TEGetHeight( (long)i, 1L, teHndl );
- p[i] = k;
- if ( k >= textHeight - viewHeight ) break;
- }
-
- HUnlock( (Handle) pHndl );
-
- *posHndl = (Handle) pHndl;
-
- return( i );
- }
-
- /***** Do Scroll *****/
- void TEScrollProc( WindowPtr window, Point thePoint )
- {
- short thePart;
- ControlHandle theControl;
- TEHandle teHndl;
- short curCtlValue, newCtlValue;
- short shift;
-
- // GetMouse( &thePoint );
- // /* GlobalToLocal( &thePoint ); */
-
- thePart = FindControl( thePoint, window, &theControl );
- if ( theControl != my(window,userCntl) ) return; // window's userCntl
-
- // window = (**theControl).contrlOwner;
- teHndl = my(window,userTE); // window's userTE
-
- switch ( thePart ) {
- case inUpButton:
- case inDownButton:
- case inPageUp:
- case inPageDown:
- thePart = TrackControl( theControl, thePoint, &myScrollProc );
- break;
- case inThumb:
- curCtlValue = GetCtlValue( theControl );
- thePart = TrackControl( theControl, thePoint, kNilActionProc );
- if ( thePart != 0 ) {
- newCtlValue = GetCtlValue( theControl );
- shift = ShiftValue( window, curCtlValue, newCtlValue );
- TEPinScroll( kShiftHorizontal, -shift, teHndl );
- // InvalRect( &(((GrafPtr)dialog)->portRect) );
- }
- break;
- }
- }
-
-
- pascal void myScrollProc( ControlHandle theControl, short thePart )
- {
- short shift;
- WindowPtr window;
- TEHandle teHndl;
-
- window = (**theControl).contrlOwner;
- teHndl = my(window,userTE); // window's userTE
-
- shift = kScrollStep1;
-
- switch( thePart ) {
- case inPageDown:
- shift = kScrollStep2;
- case inDownButton:
- SetControl( theControl, &shift );
- if ( shift != 0 ) {
- TEPinScroll( kShiftHorizontal, -shift, teHndl );
- // UpdateWindow( window );
- }
- break;
- case inPageUp:
- shift = kScrollStep2;
- case inUpButton:
- shift = -shift;
- SetControl( theControl, &shift );
- if ( shift != 0 ) {
- TEPinScroll( kShiftHorizontal, -shift, teHndl );
- // UpdateWindow( window );
- }
- break;
- }
- }
-
-
- void SetControl( ControlHandle theControl, short *shift )
- {
- WindowPtr window;
- short curCtlValue, maxCtlValue, minCtlValue;
- short newCtlValue;
-
- window = (**theControl).contrlOwner;
-
- maxCtlValue = GetCtlMax( theControl );
- curCtlValue = GetCtlValue( theControl );
- minCtlValue = GetCtlMin( theControl );
-
- newCtlValue = curCtlValue + *shift;
-
- if ( newCtlValue < minCtlValue ) newCtlValue = minCtlValue;
- if ( newCtlValue > maxCtlValue ) newCtlValue = maxCtlValue;
-
- *shift = newCtlValue - curCtlValue;
-
- if ( *shift != 0 ) {
- *shift = ShiftValue( window, curCtlValue, newCtlValue ); // window's posHndl
- SetCtlValue( theControl, newCtlValue ); }
- }
-
- /***** end of program *****/
-